<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>01React初体验</title>
  </head>
  <body>
    <div id="root"></div>
    <!-- 添加依赖 -->
    <!-- React 包含React的核心代码-->
    <!-- React-dom  React渲染不同平台的核心代码 -->
    <!-- babel  转换JSX代码  -->
    <script
      crossorigin
      src="https://unpkg.com/react@18/umd/react.development.js"
    ></script>
    <script
      crossorigin
      src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
    ></script>
    <script
      crossorigin
      src="https://unpkg.com/babel-standalone@6/babel.min.js"
    ></script>

    <script type="text/babel">
      // 创建一个根元素
      const root = ReactDOM.createRoot(document.querySelector("#root"));
      let message = "hello world";
      // 点击函数
      const clickChange = () => {
        message = "hello react";
        renderText()
      };

      // 渲染函数
      // 在根元素里面渲染元素
      const renderText = () => {
        root.render(
          <div>
            <h2>{message}</h2>
            <button onClick={clickChange}>点击修改文本</button>
          </div>
        );
      };
      renderText()
    </script>
  </body>
</html>
